define('searchList',['text!../tpl/search-list.html','tool','bootstrap'],function(Template,tool){
    var App ={
    	template:Template,
    	mixins: [tool.toor],
    	mounted:function(){
    		this.setMessage();
    		var formList=JSON.parse(sessionStorage.getItem('formList'));
    		for(var i=0,o;o=formList[i++];)
    		{
    			for(var j=0,c;c=o.child[j++];)
    			{
    				 this.formList.push(c);
    			}
    		};
    		
    	},
    	data:function(){
    		return{
    			formList:[],
    			type:'',
    			apprveTyle:'',
    			status:
    			{
    				all:true,
    				complete:false,
    				runIn:false,
    				back:false
    			},
    			unread:false,
    			message:1,
    			searchNav:{},
    			searchNavClear:true,
    			dataList:[],
    			page:1,
    			clickLoad:false,
    			ajaxUrl:'',
    			ajaxStatus:''
    		};
    	},
    	watch: {
	        '$route':function (to, from) {
	    		this.setMessage();
		    },
		    'apprveTyle':function()
		    {
		    	this.search();
		    },
		    'unread':function(val){
		       this.search();
		    }
	    },
    	methods:
    	{
    		 getSearchData:function(data)
    		 { 
    		 	 this.searchNav=data;
    		 	 this.search();
    		 },
    		 statusChange:function(key,status)
    		 {
    		 	this.status={
    				all:false,
    				complete:false,
    				runIn:false,
    				back:false
    			};
    			this.status[key]=true;
    			this.ajaxStatus=status;
    			this.search();
    		 },
    		 setMessage:function()
    		 {
    		 	    this.type=this.$route.params.id;
    		 	    this.dataList=[];
			        switch(this.type)
		    		{
		    			case 'pending':
		    			   this.message=1;//导航下标
		    			   this.ajaxUrl='/bpms/approves/todo';
		    			break;
		    			case 'agreed':
		    			   this.message=2;//导航下标
		    			   this.ajaxUrl='/bpms/approves/done';
		    			break;
		    			case 'started':
		    			   this.message=3;//导航下标
		    			   this.ajaxUrl='/bpms/approves/submit';
		    			break;
		    			case 'CC':
		    			   this.message=4;//导航下标
		    			   this.ajaxUrl='/bpms/approves/cc';
		    			break;
		    		};
		    		this.apprveTyle='';
		    		this.searchNavClear=false;
		    		var _this=this;
		    		setTimeout(function(){
		    			_this.searchNavClear=true;
		    		},30);
		    		this.unread=false;
		    		this.status=
					{
						all:true,
						complete:false,
						runIn:false,
						back:false
					};
					this.ajaxStatus='';
					this.page=1;
		    		this.search();
		    		this.approveNum();
		    		
    		 },
    		 search:function(spage){
    		 	var page=spage?(spage):1;
    		 	 var obj={
    		 	 	page:page,
					keyword:this.searchNav.Keyword?(this.searchNav.Keyword):'',
					start_time_s:this.dataFormat(this.searchNav.launchStartTime),
					start_time_e:this.dataFormat(this.searchNav.launchEndTime),
					end_time_s:this.dataFormat(this.searchNav.finishStartTime),
					end_time_e:this.dataFormat(this.searchNav.finishEndTime),
					userid:this.searchNav.people ?(this.searchNav.people.emplId):'',
					type:this.apprveTyle,
    		 	 },_this=this;
    		 	 if(this.type=='started'){
    		 	 	delete obj.userid;
    		 	 }
    		 	 if(this.type=='agreed' || this.type=='started')
    		 	 {
    		 	 	  obj['status']=this.ajaxStatus;
    		 	 }
    		 	 if(this.type=='CC')
    		 	 {
    		 	 	this.unread?(obj['is_read']=0):('')
    		 	 }
    		 	 this.myAjax({
	 	 		 	 type:"get",
	 	 		 	 tooken:false,
	 	 		 	 url: this.ajaxUrl,
	 	 		 	 data:obj,
	 	 		 	 callback:function(data)
	 	 		 	 { 
	 	 		 	 	
	 	 		 	 	if(data.data.count>=20){
	 	 		 	 		_this.clickLoad=true;
	 	 		 	 	}
	 	 		 	 	
	 	 		 	 	if(page==1 || !page)
	 	 		 	 	{
	 	 		 	 		_this.dataList=data.data.list;
	 	 		 	 	  
	 	 		 	 	}else
	 	 		 	 	{   

	 	 		 	 		for(var i=0;i<data.data.list.length;i++)
	 	 		 	 		{
	 	 		 	 			 _this.dataList.push(data.data.list[i]);
	 	 		 	 		}
	 	 		 	 		
	 	 		 	 		
	 	 		 	 	};
	 	 		 	   
	 	 		 	 	if(_this.dataList.length>=data.data.count)
	 	 		 	 	{
	 	 		 	 		_this.clickLoad=false;
	 	 		 	 	}
		 	 		 }
	 	 		 });
    		 },
    		 dataFormat:function(d)
    		 {
    		 	  if(d){
    		 	  	  return new Date(d).Format('yyyy-MM-dd');
    		 	  };
    		 	  return ''
    		 },
    		 loadMore:function()
    		 {
    		 	  this.page++;
    		 	  this.search(this.page);
    		 },
    		 allRead:function(ev)
    		 {
    		 	 if(ev.target.classList.contains('disabled')){
    		 	 	return false;
    		 	 }
                 ev.target.classList.add('disabled');
                 var _this=this;
    		 	 this.myAjax({
	 	 		 	 type:"get",
	 	 		 	 tooken:false,
	 	 		 	 url: '/bpms/approves/all-read',
	 	 		 	 callback:function(data)
	 	 		 	 {
	 	 		 	 	 if(data.code=='200')
	 	 		 	 	 {
	 	 		 	 	 	  for(var i=0;i<_this.dataList.length;i++){
	 	 		 	 	 	  	  _this.dataList[i].is_read=1;
	 	 		 	 	 	  };
	 	 		 	 	 	  _this.approveNum();
	 	 		 	 	 }
	 	 		 	 }
	 	 		 });
    		 },
    		 trClick:function(obj,index)
    		 {
    		 	 var _this=this;
    		 	 if(this.type=='CC' && obj.is_read==0){
    		 	 	  this.myAjax({
		 	 		 	 type:"get",
		 	 		 	 tooken:false,
		 	 		 	 url: '/bpms/approves/read?process_instance_id='+obj.process_instance_id,
		 	 		 	 callback:function(data)
		 	 		 	 {
		 	 		 	 	 if(data.code=='200')
		 	 		 	 	 {
		 	 		 	 	 	obj.is_read=1;
		 	 		 	 	 };
		 	 		 	 	 _this.approveNum();
		 	 		 	 }
		 	 		 });
    		 	 }
    		 	 if(obj.url)
    		 	 {
    		 	 	
    		 	 		DingTalkPC.ready(function(){
    		 	 			 	DingTalkPC.biz.util.openSlidePanel({
								    url: obj.url, //打开侧边栏的url
								    title: ' ', //侧边栏顶部标题
								    onSuccess : function(result) {
								       /*
								            调用biz.navigation.quit接口进入onSuccess, result为调用biz.navigation.quit传入的数值
								        */
								    },
								    onFail : function() {
								        /*
								            tips:点击右上角上角关闭按钮会进入onFail
								         */
								    }
								});
    		 	 		});
    		 	 }
    		 	
    		 },
    		 profile:function(userid){
    		 	 DingTalkPC.ready(function(){
    		 	 	   DingTalkPC.biz.util.open({
						    name:'profile',//页面名称
						    params:{
						        id: '123456',// String 必选 用户工号
						        corpId:'dingb4ff1079f84f8d54' //String 必选 企业id
						    },//传参
						    onSuccess : function() {
						        /**/
						    },
						    onFail : function(err) {}
						});
    		 	 	    
	 	 			 	DingTalkPC.biz.util.open({
						    name:"profile",
						    params:{
						        id: userid,
						        corpId: sessionStorage.getItem('corpId')
						    },
						    onSuccess : function() {
						       
						    },
						    onFail : function(err) {
							
						    }
						});
		 	 		});
    		 }
    		 
    	}
    };
    return {
        app:App       
    };
});